package com.cskaoyan.controller;

import com.cskaoyan.bean.bo.zy.ZYBrandCreateListBO;
import com.cskaoyan.bean.bo.zy.ZYCategoryCreateBO;
import com.cskaoyan.bean.common.BaseParam;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.common.Constant;
import com.cskaoyan.bean.marketBean.MarketBrand;
import com.cskaoyan.bean.marketBean.MarketCategory;
import com.cskaoyan.bean.vo.zy.*;
import com.cskaoyan.service.MarketRegionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商场管理模块
 *
 * @author zhangYun
 * @since 2022/12/28 16:46
 */

@RestController
@RequestMapping("admin")
public class ZYMallManagementController {


    @Autowired
    private MarketRegionService marketRegionService;

    @RequestMapping("region/list")
    /**
     *http://182.92.235.201:8083/admin/region/list
     * 行政区域之回显数据
     * @author zhangYun
     * @return
     * limit:31
     * list:[{id: 1, name: "北京市", type: 1, code: 110000, children: [{id: 32, name: "市辖区", type: 2, code: 110100,…}]
     *
     */
    public BaseRespVo list() {
        CommonData<ZYMarketRegionListVO> regionData = new CommonData<>();
        try {
            regionData = marketRegionService.list(regionData);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(regionData);
    }

    @RequestMapping("brand/list")
    /**
     * http://182.92.235.201:8083/admin/brand/list?  GET
     * page=1&limit=20&id=1046027&name=ee&sort=add_time&order=desc
     * 品牌制造商之回显品牌数据
     * @author zhangYun
     * @return
     */
    public BaseRespVo BrandList(BaseParam param, Integer id, String name) {
        CommonData<MarketBrand> brandData;
        try {
            brandData = marketRegionService.brandList(param, id, name);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(brandData);
    }

    @RequestMapping("brand/create")

    /**
     * http://182.92.235.201:8083/admin/brand/create  POST
     * {"name":"U衣裤制造商","desc":"顶级","floorPrice":"9000","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/g5v9sndds5hn9jhphme8.png"}
     * 品牌制造商之创建品牌
     * @author zhangYun
     * @return
     */
    public BaseRespVo brandCreate(@RequestBody ZYBrandCreateListBO param) {
        ZYBrandCreateListVO brandData;
        try {
            brandData = marketRegionService.brandCreate(param);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(brandData);
    }

    @RequestMapping("brand/update")
    /**
     * http://182.92.235.201:8083/admin/brand/update  POST
     * {"id":1046046,"name":"U衣裤制造商","desc":"顶级","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/g5v9sndds5hn9jhphme8.png","sortOrder":50,"floorPrice":9000,"addTime":"2022-12-29 10:50:22","updateTime":"2022-12-29 10:50:22","deleted":false}
     * 品牌制造商之编辑品牌
     * @author zhangYun
     * @return
     */
    public BaseRespVo brandUpdate(@RequestBody MarketBrand param) {
        MarketBrand result;
        try {
            result = marketRegionService.brandUpdate(param);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(result);
    }

    @RequestMapping("brand/delete")
    /**
     * http://182.92.235.201:8083/admin/brand/delete  POST
     * {"id":1046046,"name":"U衣裤制造商","desc":"顶级","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/g5v9sndds5hn9jhphme8.png","sortOrder":50,"floorPrice":9000,"addTime":"2022-12-29 10:50:22","updateTime":"2022-12-29 10:50:22","deleted":false}
     * 品牌制造商之删除品牌
     * @author zhangYun
     * @return
     */
    public BaseRespVo brandDelete(@RequestBody MarketBrand param) {
        try {
            marketRegionService.brandDelete(param);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success();
    }

    @RequestMapping("category/list")
    /**
     * http://182.92.235.201:8083/admin/category/list  GET
     * 商品类目之回显
     * @author zhangYun
     * @return
     */
    public BaseRespVo categoryList() {
        CommonData<ZYMarketCategoryListVO> result;
        try {
            result = marketRegionService.categoryList();
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(result);
    }

    @RequestMapping("category/l1")
    /**
     * http://182.92.235.201:8083/admin/category/l1  GET
     * 商品类目之一级类目回显
     * {"value":1005001,"label":"餐厨"}
     * @author zhangYun
     * @return
     */
    public BaseRespVo categoryL1() {
        CommonData<ZYMarketCategoryL1VO> result = new CommonData<>();
        try {
            result = marketRegionService.categoryL1();
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(result);
    }

    @RequestMapping("category/create")
    /**
     * http://182.92.235.201:8083/admin/category/create  POST
     * 商品类目之创建类目
     * {"name":"高级品牌","keywords":"高级","level":"L1","pid":0,"desc":"精品","iconUrl":"http://182.92.235.201:8083/wx/storage/fetch/g0h3uwzpgkhbd049bdws.jpg","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/iaxdfoyhutxbtjq4nwjc.jpg"}
     * @author zhangYun
     * @return
     */
    public BaseRespVo categoryCreate(@RequestBody ZYCategoryCreateBO param) {
        ZYCategoryCreateVO result;
        try {
            result = marketRegionService.categoryCreate(param);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(result);
    }

    @RequestMapping("category/update")
    /**
     * http://182.92.235.201:8083/admin/category/update  POST
     * 商品类目之更新类目
     * @author zhangYun
     * @return
     */
    public BaseRespVo categoryUpdate(@RequestBody MarketCategory param) {
        try {
            marketRegionService.categoryUpdate(param);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success();
    }

    @RequestMapping("category/delete")
    /**
     * http://182.92.235.201:8083/admin/category/delete  POST
     * 商品类目之删除类目
     * @author zhangYun
     * @return
     */
    public BaseRespVo categoryDelete(@RequestBody MarketCategory param) {
        try {
            marketRegionService.categoryDelete(param);
        } catch (Exception e) {
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success();
    }

}
